/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __IINPUTHANDLER_H__
#define __IINPUTHANDLER_H__

#pragma once

#include "geom/Vector.h"
#include "IModule.h"

/// Available input devices
enum eInputDevices {
	IH_KEYBOARD = 1,
	IH_MOUSE = 2, 
	IH_JOYSTICK = 4
};

/**
 * \ingroup CoreEngine
 *
 * The IInputHandler interface.<br>
 * An IInputHandler is an interface that provides access to mouse, keyboard, and joystick input.
 *
 * \date 03-28-2007
 *
 * \author juckel
 *
 */
class DLL_EXPORT IInputHandler
	: public IModule
{
public:
	IInputHandler(void);
	virtual ~IInputHandler(void);

	/// Initializes the input devices. 
	/// InputDevices are initialized through IH_KEYBOARD | IH_MOUSE | IH_JOYSTICK
	virtual bool init(HINSTANCE hInst, HWND hWnd, int inputDevices) = 0;

	void Destroy();

	/// Update the input devices and stores the data
	virtual void update() = 0;

	/// Check if a certain button is pressed. Keycodes start with DIK_*
	virtual bool isKeyPressed(int keycode) const = 0;

	/// Returns the current mouse position
	virtual math::Vector3 getRelMousePos() const = 0;

	/// Returns the absolute mouse position
	virtual const math::Vector3& getAbsMousePos() const;

	/// Inidicates, if a mouse button is pressed.
	/// 0 = LEFT_BUTTON, 1 = RIGHT_BUTTON, 2 = MIDDLE_BUTTON
	virtual bool isMouseButtonPressed(int button) const = 0;

	/// Returns the mouse buttons as a byte array
	virtual BYTE* getButtons() = 0;




	/// Returns the current relative joystick position
	/// deprecated!
	virtual math::Vector3 getRelJoystickPos() const = 0;

	/// Returns the current relative joystick position of axis1
	virtual math::Vector2f getJoystickAxis1Pos() const = 0;

	/// Returns the current relative joystick position of axis2
	virtual math::Vector2f getJoystickAxis2Pos() const = 0;

	/// Returns the absolute joystick position
	virtual const math::Vector3& getAbsJoystickPos() const;

	/// Inidicates, if a joystick button is pressed.
	virtual bool isJoystickButtonPressed(int button) const = 0;

	/// Returns the joystick buttons as a byte array
	virtual BYTE* getJoystickButtons() = 0;




	/// Indicates, if the keyboard has been successfully initialized
	const bool isKeyboardInitialized() const;

	/// Indicates, if the mouse has been successfully initialized
	const bool isMouseInitialized() const;

	/// Indicates, if the joystick has been successfully initialized
	const bool isJoystickInitialized() const;

	/// Restores the input handler object if the device was lost
	virtual void restore() = 0;

	/// Releases the input handler object
	virtual void release() = 0;

protected:
	bool bKeyboardInitialized;
	bool bMouseInitialized;
	bool bJoystickInitialized;
	math::Vector3 vMouseAbsPos;      ///< Absolute Mouse position
	math::Vector3 vJoystickAbsPos;
};

/**
 *  Initialize the input interfaces
 *  \param inputhandler	The inputhandler type to use. <br>Possible values are IH_KEYBOARD, IH_MOUSE and IH_JOYSTICK or any combination.
 */
DLL_EXPORT
bool coreInitInput(int inputhandler);

/**
 *  Returns a reference to the current input handler object.
 */
DLL_EXPORT
IInputHandler* coreGetInputHandler();

#endif
